Hệ thống tạo mã vạch trong PHP bằng mã nguồn

1 <?php
2 ?>
3 <style>
4 div.b128{
5  border-left: 1px black solid;
6  height: 30px;
7 }
8 </style>
9
10 <?php

11 global
$char128asc,$char128charWidth;
12 $char128asc=
' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
13 $char128wid = array(
14  
'212222','222122','222221','121223','121322','131222','122213','122312','132212','221213', // 0-9
15  
'221312','231212','112232','122132','122231','113222','123122','123221','223211','221132', // 10-19
16  
'221231','213212','223112','312131','311222','321122','321221','312212','322112','322211', // 20-29
17  
'212123','212321','232121','111323','131123','131321','112313','132113','132311','211313', // 30-39
18  
'231113','231311','112133','112331','132131','113123','113321','133121','313121','211331', // 40-49
19  
'231131','213113','213311','213131','311123','311321','331121','312113','312311','332111', // 50-59
20  
'314111','221411','431111','111224','111422','121124','121421','141122','141221','112214', // 60-69
21  
'112412','122114','122411','142112','142211','241211','221114','413111','241112','134111', // 70-79
22  
'111242','121142','121241','114212','124112','124211','411212','421112','421211','212141', // 80-89
23  
'214121','412121','111143','111341','131141','114113','114311','411113','411311','113141', // 90-99
24  
'114131','311141','411131','211412','211214','211232','23311120' ); // 100-106
25
26 ///
/Define Function
27 function bar128($text) {
// Part 1, make list of widths
28  
global $char128asc,$char128wid;
29  $w = $char128wid[$sum =
104]; // START symbol
30  $onChar=
1;
31  
for($x=0;$x<strlen($text);$x++) // GO THRU TEXT GET LETTERS
32  
if (!( ($pos = strpos($char128asc,$text[$x])) === false )){ // SKIP NOT FOUND CHARS
33  $w.= $char128wid[$pos];
34  $sum += $onChar++ * $pos;
35  }
36  $w.= $char128wid[ $sum %
103 ].$char128wid[106]; //Check Code, then END
37  
//Part 2, Write rows
38  $html=
"<table cellpadding=0 cellspacing=0><tr>";
39  
for($x=0;$x<strlen($w);$x+=2) // code 128 widths: black border, then white space
40  $html .=
"<td><div class=\"b128\" style=\"border-left-width:{$w[$x]};width:{$w[$x+1]}\"></div></td>";
41  
return "$html<tr><td colspan=".strlen($w)." align=left><font family=arial size=2>$text</td></tr></table>";
42 }
43 ?>


Gõ tìm kiếm nhanh...